use std::{cell::RefCell, rc::{Rc, Weak}, sync::Arc};


#[derive(Debug)]
struct Node {
    value: i32,
    child: RefCell<Vec<Rc<Node>>>,
    parent: RefCell<Weak<Node>>
}

fn main() {
    println!("Hello, world!");

    let leaf = Rc::new(
        Node {
            value: 21,
            child: RefCell::new(vec![]),
            parent: RefCell::new(Weak::new())
        }
    );

    let root = Rc::new(
        Node {
            value: 1,
            child: RefCell::new(vec![]),
            parent: RefCell::new(Weak::new())
        }
    );

    // root.child.borrow_mut().push(Rc::clone(&leaf));
    root.child.borrow_mut().push(leaf.clone());
    // Rc::downgrade 创建weak引用
    *leaf.parent.borrow_mut() = Rc::downgrade(&root);
    
    println!("{:?}", leaf.parent.borrow().upgrade());

    let a = Arc::new(1);
    let b = Arc::clone(&a);
    let c = a.clone();
}
